#! /usr/bin/python
# -*- coding: UTF-8 -*-

f = open('rank.txt')
lines = f.readlines()
f.close()

from pychartdir import *

res = [0]*1500
n = len(lines)

for i in lines:
    deg = int(i.split(' : ')[1][:-1])
    res[deg] = res[deg] + 1

labels = [str(i) for i in xrange(148)]
print res, labels
c = XYChart(1300,740,0xffffc0, 0x000000, 1)
c.setPlotArea(40,20,1200,660)
c.addLegend(45,12,0,'',8).setBackground(Transparent)

data0 = [i/float(n) for i in res[1:40]]
data1 = [x**(-1.5) for x in xrange(1,40)]

# Set the y axis label format to nn%
c.yAxis().setLabelFormat("{value}")

# Set the labels on the x axis
c.xAxis().setLabels(labels[1:40])

# Add a line layer to the chart
layer = c.addLineLayer()

# Add the first line. Plot the points with a 7 pixel square symbol
layer.addDataSet(data0, 0xcf4040, "people").setDataSymbol(SquareSymbol, 7)

# Add the second line. Plot the points with a 9 pixel dismond symbol
layer.addDataSet(data1, 0x40cf40, "power law").setDataSymbol(DiamondSymbol, 9)

# Enable data label on the data points. Set the label format to nn%.
layer.setDataLabelFormat("{value|0}p")

# output the chart
c.makeChart("symbolline.png")
